libostree: Add an assert to pacify clang-analyzer
authorColin Walters <walters@verbum.org>
Mon, 14 Oct 2019 13:25:46 +0000 (13:25 +0000)
committerColin Walters <walters@verbum.org>
Tue, 15 Oct 2019 12:40:54 +0000 (12:40 +0000)
Got this error when trying to rebase libostree in RHEL:

```
Error: CLANG_WARNING: [#def1]
libostree-2019.2/src/libostree/ostree-repo-checkout.c:375:21: warning: Access to field 'disable_xattrs' results in a dereference of a null pointer (loaded from variable 'repo')
```

I think what's happening is it sees us effectively testing
`if (repo == NULL)` via the `while (current_repo)`.  Let's
tell it we're sure it's non-null right after the loop.

src/libostree/ostree-repo-checkout.c

index 49ec995f6a330dd82a7c53153c28b70353b54df2..8dd14640f5ec4e280c4ab59388256f2d94e6f029 100644 (file)
@@ -717,6 +717,8 @@ checkout_one_file_at (OstreeRepo                        *repo,
             }
           current_repo = current_repo->parent_repo;
         }
+      /* Pacify clang-analyzer which sees us testing effectively if (repo == NULL) */
+      g_assert (repo);
 
       need_copy = (hardlink_res == HARDLINK_RESULT_NOT_SUPPORTED);
     }